﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Omabar.BLL;
using Omabar.Model;

namespace Omabar.CMS.Pages
{
    public partial class RoutePrint : System.Web.UI.Page
    {
        public string routeTrips = null;
        protected void Page_Load(object sender, EventArgs e)
        {
            string routeid = this.Request["routeid"];

            Route_BLL routeBLL = new Route_BLL();
            ROUTE route = routeBLL.GetModel(routeid);

            Trip_BLL tripBLL = new Trip_BLL();
                List<TRIP> tripList = tripBLL.GetModels(string.Format("SELECT TRIP_ID,TRIP_NAME,TRIP_FOOD,TRIP_DES FROM TRIP WHERE TRIP_ID IN (SELECT TRIP_ID FROM ROUTE_TRIP WHERE ROUTE_ID='{0}')", route.ROUTE_ID));
                routeTrips =  RouteFactory.CreateTrips(tripList);


                this.Label02.InnerHtml = routeTrips;
                this.titleDiv.InnerHtml = route.ROUTE_NAME+"(行程单)";
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Charset = "";
            HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=行程单.doc");
            this.Button1.Visible = false;
            //HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
            HttpContext.Current.Response.Charset = "UTF-8";
            HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.UTF8; 
            //更改ContentType的值为ms-word即可实现导出到Word  
            HttpContext.Current.Response.ContentType = "application/ms-word";//image/JPEG;text/HTML;image/GIF;vnd.ms-excel/msword  
            this.Page.EnableViewState = false;
            System.IO.StringWriter tw = new System.IO.StringWriter();
            System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(tw);
            this.RenderControl(hw);
            HttpContext.Current.Response.Write(tw.ToString());
            HttpContext.Current.Response.End();
            this.Button1.Visible = true;
        }
    }
}